﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;
using System.Text;

namespace com.huigo.Admin.Web.insurer
{
    public partial class InsList : BasePage
    {
        private int pageIndex
        {
            get
            {
                return com.loto.Common.TypeParse.StrToInt(Request.QueryString["page"], 1);
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void pageInfo_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindData();
        }

        protected void BindData()
        {
            List<RequestFuncParams> argList = new List<RequestFuncParams>();
            argList.Add(new RequestFuncParams("pageSize", pageInfo.PageSize.ToString()));
            argList.Add(new RequestFuncParams("pageIndex", pageIndex.ToString()));
            BaseService baseService = new BaseService();
            ParserXml parser = baseService.RequestEntryService(Dict.ERequestFunc.GET_INS_COMPANY, argList);

            if (parser != null && parser.RowsCount > 0)
            {
                pageInfo.RecordCount = Convert.ToInt16(parser["RecordCount", 0]);
                pageInfo.CurrentPageIndex = pageIndex;
                pageInfo.PageURLFormat = GetPagerUrl();
                StringBuilder sb = new StringBuilder();
                sb.Append("<table><thead><tr><th style=\"width: 20%\">保险公司名称</th><th style=\"width: 20%\">保险公司简称</th><th style=\"width: 20%\">LOGO</th><th style=\"width: 20%\">保险公司网址</th><th style=\"width: 15%\">保险公司订单号前缀</th><th>操作</th></tr></thead><tbody>");
                string content = "<tr><td>{0}</td><td>{1}</td><td/>{2}</td><td>{3}</td><td>{4}</td><td><a href=\"AddIns.aspx?sid={5}&keepThis=true&amp;TB_iframe=true&amp;height=500&amp;width=850\" title=\"修改供应商- {0}\" class=\"thickbox\">修改</a></td></tr>";
                for (int i = 0; i < parser.RowsCount; i++)
                {
                    sb.AppendFormat(content, parser["CompanyName", i].ToString(), parser["CompanyShortName", i].ToString(), parser["CompanyLogo", i].ToString(), parser["CompanyWebsite", i].ToString(), parser["CompanyEx", i].ToString(), parser["CompanyId", i].ToString());
                }
                sb.Append("</tbody></table>");
                litIns.Text = sb.ToString();
            }
            else
                litIns.Text = string.Empty;


        }

        private string GetPagerUrl()
        {
            string url = "InsList.aspx?";
            url += "page={0}";
            return url;
        }

    }
}
